<style type="text/css">
    .action-cell {
        margin-bottom: 20px;
        width: 100%;
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-pack: distribute;
        justify-content: space-between;
        align-items: center;
        margin-right: 20%;
    }

    .search-block {
        display: flex;
        margin-bottom: 10px;
    }

    .input-search {
        margin-right: 10px;
    }
</style>
<template>
    <div>
        <div class="action-cell">
            <div class="list-action-btn">
                <Button type="error" size="large" @click="addIsShow =true">添加油料储存数据</Button>
            </div>
        </div>
        <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>
        <!--<div style="margin: 10px;overflow: hidden">-->
        <!--<div style="float: right;">-->
        <!--<Page :total="total" size="large" show-total :current="current" show-elevator show-sizer-->
        <!--@on-change="changePage"></Page>-->
        <!--</div>-->
        <!--</div>-->
        <!--添加-->
        <Modal v-model="addIsShow" title="添加" @on-ok="handleSubmit('formValidate')"
               @on-cancel="setPwdIsShow =false">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
                <Form-item label="油料存储量的值" prop="value">
                    <i-input v-model="formValidate.value" placeholder="请输入油料存储量的值"></i-input>
                </Form-item>
                <Form-item label="油料类型" prop="value">
                    <i-select v-model="formValidate.typeId" placeholder="请选择油料类型">
                        <template v-for="(item,index) in oilTypeData">
                            <i-option :value="item.Id">{{item.Value}}</i-option>
                        </template>
                    </i-select>
                </Form-item>
            </Form>
        </Modal>
    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                self: this,
                tableData: [],
                //添加
                formValidate: {
                    //添加字段
                    value: '',
                    typeId: '',
                },
                addIsShow: false,
                ruleValidate: {},
                //油料类型选择数据和
                oilTypeData: [],
                tableColumns: [
                    {
                        title: '油料类型',
                        key: 'OilTypeName',
                        align: 'center',
                    },
                    {
                        title: '油料存储量的值',
                        key: 'OilValue',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {

                            return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'error',
                                            size: 'small'
                                        },
                                        style: {
                                            'margin-right': '10px',
                                        },
                                        on: {
                                            click: () => {
                                                this.remove(params.row.Id)

                                            }
                                        }
                                    }, '删除'),

                                ]
                            )

                        }
                    }
                ]
            }
        },
        mounted() {
            this.mockTableData();
            this.getOilTypeData();
        },
        components: {},
        methods: {
            handleEdit(row) {
                this.$set(row, '$isEdit', true)
            },
            handleSave(row) {
                this.$set(row, '$isEdit', false);

                this.tableEditSave(row);
                console.log('值:', row);

            },
            handleSubmit(name) {
                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.comfirmModifyPS(model);
                })
            },
            comfirmModifyPS: function (model) {
                let that = this;
                let params = that.$qs.stringify(model);
                apiUtil.post(that, apiUtil.urls.AddOilData, params, function (res) {
                    that.mockTableData();
                });
            },
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id,
                            value: ''
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            //列表总数据
            mockTableData() {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.OilDataList, params, function (res) {
                    that.$Loading.finish();
                    that.tableData = res.Msg;

                    console.log('res:', res)
                });

            },
            getOilTypeData: function () {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.OilTypeList, params, function (res) {
                    that.$Loading.finish();
                    that.oilTypeData = res.Msg;

                });
            },
            //删除
            remove(id) {
                let that = this;
                this.$Modal.confirm({
                    title: '用户信息',
                    content: `是否删除此记录`,
                    onOk: function () {
                        this.$Loading.start();
                        let para = {
                            id: id,
                        };
                        let params = that.$qs.stringify(para);
                        apiUtil.post(that, apiUtil.urls.DelOilData, params, function (res) {
                            that.mockTableData();
                        });
                    }
                })
            },
        },
    }
</script>